package com.ltkj.ticket.controller;

import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.ticket.domain.TicActivityBusiness;
import com.ltkj.ticket.service.ITicActivityBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动票Controller
 * 
 * @author ruoyi
 * @date 2023-08-31
 */
@Api(tags = "活动票")
@RestController
@RequestMapping("/business")
public class TicActivityBusinessController extends BaseController
{
    @Autowired
    private ITicActivityBusinessService ticActivityBusinessService;

    /**
     * 查询活动票列表
     */
    @ApiOperation("查询活动票列表")
    @RequiresPermissions("ticket:business:list")
    @GetMapping("/list")
    public TableDataInfo list(TicActivityBusiness ticActivityBusiness)
    {
        startPage();
        List<TicActivityBusiness> list = ticActivityBusinessService.selectTicActivityBusinessList(ticActivityBusiness);
        return getDataTable(list);
    }
    /**
     * 查询活动票列表优惠券
     */
    @ApiOperation("查询活动票列表优惠券")
    @GetMapping("/listCoupontem")
    public AjaxResult listCoupontem(TicActivityBusiness ticActivityBusiness)
    {
        List<TicActivityBusiness> list = ticActivityBusinessService.selectTicActivityBusinessList(ticActivityBusiness);
        return success(list);
    }
    /**
     * 导出活动票列表
     */
    @ApiOperation("导出活动票列表")
    @RequiresPermissions("ticket:business:export")
    @Log(title = "活动票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicActivityBusiness ticActivityBusiness)
    {
        List<TicActivityBusiness> list = ticActivityBusinessService.selectTicActivityBusinessList(ticActivityBusiness);
        ExcelUtil<TicActivityBusiness> util = new ExcelUtil<TicActivityBusiness>(TicActivityBusiness.class);
        util.exportExcel(response, list, "活动票数据");
    }

    /**
     * 获取活动票详细信息
     */
    @ApiOperation("获取活动票详细信息")
    @RequiresPermissions("ticket:business:query")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(ticActivityBusinessService.selectTicActivityBusinessByActivityId(activityId));
    }

    /**
     * 新增活动票
     */
    @ApiOperation("新增活动票")
    @RequiresPermissions("ticket:business:add")
    @Log(title = "活动票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicActivityBusiness ticActivityBusiness)
    {
        return toAjax(ticActivityBusinessService.insertTicActivityBusiness(ticActivityBusiness));
    }

    /**
     * 修改活动票
     */
    @ApiOperation("修改活动票")
    @RequiresPermissions("ticket:business:edit")
    @Log(title = "活动票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicActivityBusiness ticActivityBusiness)
    {
        return toAjax(ticActivityBusinessService.updateTicActivityBusiness(ticActivityBusiness));
    }

    /**
     * 删除活动票
     */
    @ApiOperation("删除活动票")
    @RequiresPermissions("ticket:business:remove")
    @Log(title = "活动票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(ticActivityBusinessService.deleteTicActivityBusinessByActivityIds(activityIds));
    }

    /**
     * 获取活动票详细信息
     */
    @ApiOperation("活动票下架")
    @RequiresPermissions("ticket:business:offshelf")
    @Log(title = "活动票", businessType = BusinessType.OFFSHELF)
    @GetMapping(value = "/offshelf/{activityId}")
    public AjaxResult offshelf(@PathVariable("activityId") Long activityId) {
        return  ticActivityBusinessService.offshelf(activityId);
    }

    /**
     * 获取活动票详细信息
     */
    @ApiOperation("活动票上架")
    @RequiresPermissions("ticket:business:onshelf")
    @Log(title = "活动票", businessType = BusinessType.ONSHELF)
    @GetMapping(value = "/onshelf/{activityId}")
    public AjaxResult onshelf(@PathVariable("activityId") Long activityId) {
        return  ticActivityBusinessService.onshelf(activityId);
    }

    /**
     * 获取活动票详细信息
     */
    @ApiOperation("活动票下拉")
    @RequiresPermissions("ticket:business:select")
    @Log(title = "活动票", businessType = BusinessType.OTHER)
    @GetMapping(value = "/select")
    public AjaxResult select() {
        return ticActivityBusinessService.select();
    }
}
